package com.dearbinge.opentapi.content.shopganre;

import com.dearbinge.data.api.shogenre.ShopGenreService;
import com.dearbinge.utils.ResultMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Api(description = "商品类目")
@RestController
@RequestMapping("/shopgenre")
@EnableAutoConfiguration
public class ShopGenreController {


    @Autowired
    private ShopGenreService shopGenreService;

    @ApiOperation(value = "获取首页类目", notes = "获取首页类目")
    @RequestMapping(value = "/getIndexGenre", method = RequestMethod.GET)
    public ResultMsg<List<Map>> getIndexGenre() {
        try {
            List<Map> list = shopGenreService.getIndexGenre();
            return ResultMsg.ok(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultMsg.error(500, "系统异常");
    }



    @ApiOperation(value = "商品类目", notes = "商品类目")
    @ApiImplicitParam(name = "parentId", value = "一级类目id", paramType = "query")
    @RequestMapping(value = "/getShopGenre", method = RequestMethod.GET)
    public ResultMsg<List<Map>> getShopGenre(Integer parentId) {
        if (parentId == null || parentId.equals("")) {
            parentId = 0;
        }
        try {
            List<Map> list = shopGenreService.getShopGenre(parentId);
            return ResultMsg.ok(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultMsg.error(500, "系统异常");
    }


}
